﻿using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Linq;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;

using HT.Model;
using HT.Persistency;
using HT.Service;

namespace HT.Workflow
{
    public sealed partial class ReimbursementWorkflow : StateMachineWorkflowActivity
    {
        private ReimbursementInfo internalReimbursementInfo;        

        public ReimbursementWorkflow()
        {
            InitializeComponent();
        }        

        public ReimbursementInfo ReimbursementInfoProperty
        {
            get { return internalReimbursementInfo; }
            set { internalReimbursementInfo = value; }
        }        

        private void createActivity_ExecuteCode(object sender, EventArgs e)
        {
            ReimbursementPersistency reimbursementPersistency = new ReimbursementPersistency();
            internalReimbursementInfo.InstanceID = this.WorkflowInstanceId;
            internalReimbursementInfo.Status = WorkflowStatus.Running.ToString();
            internalReimbursementInfo.CreateDate = DateTime.Now;

            EmployeeInfoPersistency employeeInfoPersistency = new EmployeeInfoPersistency();
            string currentUserId = internalReimbursementInfo.Owner;
            string nextHandler = employeeInfoPersistency.GetReportManagerIDByUser(currentUserId);
            internalReimbursementInfo.NextHandler = nextHandler;
            reimbursementPersistency.insertReimbursementInfo(internalReimbursementInfo);
        }

        private void changeNextHandlerActivity_ExecuteCode(object sender, EventArgs e)
        {
            EmployeeInfoPersistency employeeInfoPersistency = new EmployeeInfoPersistency();
            internalReimbursementInfo.NextHandler = employeeInfoPersistency.GetEmployeeWithRole(EmployeeRole.AC);
            ReimbursementPersistency reimbursementPersistency = new ReimbursementPersistency();
            reimbursementPersistency.updateReimbursementInfo(internalReimbursementInfo);
        }  

        public ReimbursementEventArgs approveEventArgs = default(HT.Service.ReimbursementEventArgs);
        public ReimbursementEventArgs rejectEventArgs = default(HT.Service.ReimbursementEventArgs);

        private void reportManagerApproveActivity_ExecuteCode(object sender, EventArgs e)
        {
            ReimbursementPersistency reimbursementPersistency = new ReimbursementPersistency();
            ReimbursementInfo newReimbursementInfo = approveEventArgs.ReimbursementProperty;
            internalReimbursementInfo.RMSuggestion = newReimbursementInfo.RMSuggestion;

            EmployeeInfoPersistency employeeInfoPersistency = new EmployeeInfoPersistency();
            internalReimbursementInfo.NextHandler = employeeInfoPersistency.GetEmployeeWithRole(EmployeeRole.AC);
           
            reimbursementPersistency.updateReimbursementInfo(internalReimbursementInfo);
            
        }

        private void reportManagerRejectActivity_ExecuteCode(object sender, EventArgs e)
        {
            ReimbursementPersistency reimbursementPersistency = new ReimbursementPersistency();
            ReimbursementInfo newReimbursementInfo = rejectEventArgs.ReimbursementProperty;
            internalReimbursementInfo.RMSuggestion = newReimbursementInfo.RMSuggestion;

            internalReimbursementInfo.NextHandler = "";

            reimbursementPersistency.updateReimbursementInfo(internalReimbursementInfo);  
        }        

        private void accountantApproveActivity_ExecuteCode(object sender, EventArgs e)
        {
            ReimbursementPersistency reimbursementPersistency = new ReimbursementPersistency();
            ReimbursementInfo newReimbursementInfo = approveEventArgs.ReimbursementProperty;
            internalReimbursementInfo.ACSuggestion = newReimbursementInfo.ACSuggestion;

            EmployeeInfoPersistency employeeInfoPersistency = new EmployeeInfoPersistency();
            internalReimbursementInfo.NextHandler = employeeInfoPersistency.GetEmployeeWithRole(EmployeeRole.VP);

            reimbursementPersistency.updateReimbursementInfo(internalReimbursementInfo);
        }

        private void accountantRejectActivity_ExecuteCode(object sender, EventArgs e)
        {
            ReimbursementPersistency reimbursementPersistency = new ReimbursementPersistency();
            ReimbursementInfo newReimbursementInfo = rejectEventArgs.ReimbursementProperty;
            internalReimbursementInfo.ACSuggestion = newReimbursementInfo.ACSuggestion;

            internalReimbursementInfo.NextHandler = "";

            reimbursementPersistency.updateReimbursementInfo(internalReimbursementInfo);    
        }

        private void vicePresidentApproveActivity_ExecuteCode(object sender, EventArgs e)
        {
            ReimbursementPersistency reimbursementPersistency = new ReimbursementPersistency();
            ReimbursementInfo newReimbursementInfo = approveEventArgs.ReimbursementProperty;
            internalReimbursementInfo.VPSuggestion = newReimbursementInfo.VPSuggestion;

            EmployeeInfoPersistency employeeInfoPersistency = new EmployeeInfoPersistency();
            internalReimbursementInfo.NextHandler = employeeInfoPersistency.GetEmployeeWithRole(EmployeeRole.PR);

            reimbursementPersistency.updateReimbursementInfo(internalReimbursementInfo);
        }

        private void vicePresidentRejectActivity_ExecuteCode(object sender, EventArgs e)
        {
            ReimbursementPersistency reimbursementPersistency = new ReimbursementPersistency();
            ReimbursementInfo newReimbursementInfo = rejectEventArgs.ReimbursementProperty;
            internalReimbursementInfo.VPSuggestion = newReimbursementInfo.VPSuggestion;

            internalReimbursementInfo.NextHandler = "";

            reimbursementPersistency.updateReimbursementInfo(internalReimbursementInfo);  
        }

        private void presidentApproveActivity_ExecuteCode(object sender, EventArgs e)
        {
            ReimbursementPersistency reimbursementPersistency = new ReimbursementPersistency();
            ReimbursementInfo newReimbursementInfo = approveEventArgs.ReimbursementProperty;
            internalReimbursementInfo.PRSuggestion = newReimbursementInfo.PRSuggestion;

            internalReimbursementInfo.NextHandler = "";

            reimbursementPersistency.updateReimbursementInfo(internalReimbursementInfo);
        }

        private void presidentRejectActivity_ExecuteCode(object sender, EventArgs e)
        {
            ReimbursementPersistency reimbursementPersistency = new ReimbursementPersistency();
            ReimbursementInfo newReimbursementInfo = rejectEventArgs.ReimbursementProperty;
            internalReimbursementInfo.PRSuggestion = newReimbursementInfo.PRSuggestion;

            internalReimbursementInfo.NextHandler = "";

            reimbursementPersistency.updateReimbursementInfo(internalReimbursementInfo); 
        }          
       
    }
}
